/**
    [Filename]
    Purpose: [Purpose]

    @author Jason Wojcik
    @version [version]
*/

#include "CSurface.h"

//CSurface Constructor
CSurface::CSurface(){
}

//OnLoad function - returns a loaded surface
SDL_Surface* CSurface::OnLoad(char* File){

    //Initalize temp and return surfaces
    SDL_Surface* Surf_Temp = NULL;
    SDL_Surface* Surf_Return = NULL;

    //return Null if surface cannot be loaded
    if((Surf_Temp = IMG_Load(File)) == NULL) return NULL;

    //Set the return surface to the corrected surface
    Surf_Return = SDL_DisplayFormatAlpha(Surf_Temp);

    //Free the temp resource
    SDL_FreeSurface(Surf_Temp);

    return Surf_Return;

}

//draws the full surface
bool CSurface::OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src,
    int X, int Y){

    //return false if the destination or source surfaces are NULL
    if(Surf_Dest == NULL || Surf_Src == NULL) return false;

    SDL_Rect DestR;

    DestR.x = X;
    DestR.y = Y;

    SDL_BlitSurface(Surf_Src, NULL, Surf_Dest, &DestR);

    return true;

    }

/*
draws the sub-surface from a sprite sheet
@param screen surface where image is applied
@param the surface of the image
@param X, Y the coordinates on screen where the surface is drawn
@param X2, Y2 the upper left corner in the spite sheet
@param W, H the width and heigh of the sub-image within the sprite sheet
@return
*/
bool CSurface::OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src,
    int X, int Y, int X2, int Y2, int W, int H){

    //return false if the destination or source surfaces are NULL
    if(Surf_Dest == NULL || Surf_Src == NULL) return false;

    SDL_Rect DestR;

    DestR.x = X;
    DestR.y = Y;

    SDL_Rect SrcR;

    SrcR.x = X2;
    SrcR.y = Y2;
    SrcR.w = W;
    SrcR.h = H;

    SDL_BlitSurface(Surf_Src, &SrcR, Surf_Dest, &DestR);

    return true;

    }

//sets the transparent color for the surface
bool CSurface::Transparent(SDL_Surface* Surf_Dest, int R, int G, int B) {
    if(Surf_Dest == NULL) {
        return false;
    }

    SDL_SetColorKey(Surf_Dest, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(Surf_Dest->format, R, G, B));

    return true;
}
